<?php
    include('header.php');
    include('submenu.php');
    
    $sql = "SELECT customer.* , customer_company.* FROM customer LEFT JOIN customer_company ON(customer.cc_id=customer_company.cc_id) ORDER BY customer_company.cc_code";
    $result = $db->Execute($sql);
    $i = 1;
    $customer_list = '';
    while (!$result->EOF){
        if(($i++)%2){
            $tr_class = 'even';
        }else{
            $tr_class = 'odd';
        }
        
        $customer_list .=<<<packing_list
            <tr class="{$tr_class}" id="{$result->fields['c_id']}">
                <td class="dragHandle">{$result->fields['cc_code']}</td>
                <td class="text_center">{$result->fields['c_no']}</td>
                <td class="text_middle">{$result->fields['c_name']}</td>
                <td class="text_center text_middle" style="width:130px;"><a href="?m=customer&s=customer_edit&c_id={$result->fields['c_id']}" title="แก้ไข"><img src="images/edit.png" class="action_img" /></a> / <a href="javascript:delete_customer({$result->fields['c_id']})" title="ลบ"><img src="images/delete.png" class="action_img" /></a></td>
            </tr>
packing_list;
        
        $result->MoveNext();
    }
    $result->Close();
?>
    <div class="grid_18" id="contents">
        
        <div id="contents_">
            
            <div id="add-from-link"><a href="?m=customer&s=customer_add" title="Add Customer">Add Customer <img src="images/add.png" /></a></div>
            
            <table class="tb_list" id="table-1">
                <tr class="tr_header nodrop nodrag">
                    <th>Company Code</th>
                    <th>Cus. No.</th>
                    <th>Cus. Name</th>
                    <th style="width:100px;">แก้ไข / ลบ</th>
                </tr>
                <?php echo $customer_list; ?>
            </table>
            
        </div>
        
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script>
    $(document).ready(function() {
        
    });
    
    function delete_customer(c_id){
        if(confirm('ต้องการลบข้อมูล?')){
            window.location = '?m=customer&s=customer_delete_query&c_id='+c_id;
        }
    }
</script>